<!--  -->
<template>
    <div >
<!-- 公司信息 -->
        <CompanyInfo  :companyInfo="companyInfo" :urls="urls" @addPost="addPost" @editImg="editImg" @editInfo="editInfo"/>
        <el-dialog
          :visible.sync="editVisible"
          :before-close="handleEditClose"
          width="50%"
          title="修改公司信息"
           >
        <CompanyEdit :param="item.companyInfo" @saveEdit='saveEdit'/>
        </el-dialog>
        <!-- 轮播图修改 -->
        <el-dialog
          :visible.sync="editImgVisible"
          :before-close="handleEditClose"
          width="50%"
          title="修改轮播图"
           >
        <CompanyImg :cid="companyInfo.id" @saveImg='saveImg'/>
        </el-dialog>
        <!-- 岗位信息 -->
        <el-row>
        <CompanyPostTable ref="table" :postInfoParam = "postInfo" :height="400" :selectionData ="selectionData" />
        </el-row>
    </div>

  </template>

<script>
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
// 例如：import 《组件名称》 from '《组件路径》';
import CompanyEdit from '@/components/company/CompanyEdit.vue'
import CompanyImg from '@/components/company/CompanyImg.vue'
import CompanyInfo from '@/components/company/CompanyInfo.vue'
import CompanyPostTable from '@/components/companyPost/CompanyPostTable.vue'
export default {
  name: 'ICompany',
  // import引入的组件需要注入到对象中才能使用
  components: { CompanyEdit, CompanyImg, CompanyInfo, CompanyPostTable },
  data () {
    // 这里存放数据
    return {
      editVisible: false,
      editImgVisible: false,
      // 传递给修改主键的参数
      item: {
        companyInfo: {},
        urls: []
      },
      companyInfo: {
        id: '1',
        name: '贵大职业划水公司',
        phone: 15990152622,
        email: '1617511878@qq.com',
        address: '贵州省贵阳市花溪区贵州大学西校区',
        url: 'www.123.com',
        size: '500-1000',
        type: '互联网',
        time: '1920-02-20',
        description: '阿达到家了卡萨丁记录卡受打击考拉手机打蜡受打击啊索拉卡登记阿卡拉受打击卡拉受打击立卡手机打克拉拉送达了手机打'
      },
      urls: [
      ],
      selectionData: {
        cid: '',
        pageSize: 7,
        pageNo: 1
      },
      postInfo: [
        {
          id: 1,
          companyName: 'sdas',
          name: '养牛',
          address: '花溪公园',
          experience: '无需经验',
          qualification: '本科',
          require: '要求有这样那样的asdasdasssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss',
          treatment: '五险一金。。dadadadasdasdasdasdasasdasdasdasdasddasd。。',
          responsibility: '工作负责。。。。asddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd',
          salaryFrom: '2000',
          salaryTo: '9000',
          way: '月',
          lastTime: '2024-06-14',
          // 标签是重要的筛查方式
          postLab: [
            'python', 'java', 'mybatis', 'vue', 'mybatis-plus'
          ]
        },
        {
          id: 2,
          companyName: 'sdas',
          name: '养牛',
          address: '花溪公园',
          experience: '无需经验',
          qualification: '本科',
          require: '要求有这样那样',
          treatment: '五险一金。。。。',
          responsibility: '工作负责。。。。',
          salaryFrom: '2000',
          salaryTo: '9000',
          way: '月',
          lastTime: '2024-06-15',
          // 标签是重要的筛查方式
          postLab: [
            'python', 'java', 'mybatis'
          ]
        }

      ]
    }
  },
  // 监听属性 类似于data概念
  computed: {},
  // 监控data中的数据变化
  watch: {},
  // 方法集合
  methods: {
    editInfo () {
      console.log('编辑信息')
      this.item.companyInfo = this.companyInfo
      this.editVisible = true
    },
    handleEditClose (done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          console.log('关闭')
          done()
        })
        .catch(_ => {})
    },
    saveEdit (item) {
      // console.log('父组键中的item', item)
      // this.companyInfo = item.companyInfo
      // this.urls = item.urls
      this.editVisible = false
    },
    editImg () {
      this.item.urls = this.urls
      this.editImgVisible = true
    },
    saveImg () {
      this.initUrls(this.companyInfo.id)
      console.log('刷新图片：', this.urls)
    },
    addPost () {
      // console.log(this.$refs.table.addPost())
      this.$nextTick(() => {
        this.$refs.table.addPost()
      })
    },
    initUrls (cid) {
      const qurl = '/photos/getCompanyPhotosByCid/' + cid
      this.$get(qurl).then(res => {
        if (res.data !== null || res.data !== '') {
          this.urls = res.data
        }
        console.log('轮播图列表：', this.urls)
      })
    },
    getCompanyInfo (uid) {

    }

  },
  // 生命周期 - 创建完成（可以访问当前this实例）
  created () {
    console.log('传递公司名称为:', this.$route.query.companyName)
    let url = ''
    if (this.$route.query.companyName) {
      url = '/company/getInfoByName/' + this.$route.query.companyName
    } else {
      url = '/company/getInfoByUid/' + this.$store.state.userInfo.uid
    }
    this.$get(url).then(res => {
      this.companyInfo = res
      this.$store.commit('setCName', this.companyInfo.name)
      console.log(res)
    })
    this.selectionData.cid = this.companyInfo.id
    this.initUrls(this.companyInfo.id)
  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted () {

  },
  beforeCreate () {}, // 生命周期 - 创建之前
  beforeMount () {}, // 生命周期 - 挂载之前
  beforeUpdate () {}, // 生命周期 - 更新之前
  updated () {}, // 生命周期 - 更新之后
  beforeDestroy () {}, // 生命周期 - 销毁之前
  destroyed () {}, // 生命周期 - 销毁完成
  activated () {} // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>
<style lang='less' scoped>
.imgBlock {
  width: 250px;
  height: 250px;
  margin: 50px;
}
.imgBlock .el-image {
  width: 250px;
  /* height: 250px; */
}
.imgBlock img {
  width: 250px;
  height: 250px;
}
.el-descriptions__header {
  text-align: center;
  margin: 50px;
  position: relative;
}
.el-descriptions__title {
  font-size: 20px;
  position: absolute;
  left: 40%;
}
.el-descriptions-item__label:not(.is-bordered-label) {
  font-weight: 500;
  font-size: 16px;
  white-space: nowrap;
  padding: 0 3px;
  color: #023344;
}
.el-descriptions-item__content {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  word-break: keep-all;
}
</style>
